from myapp.utils.connection import POOL


def heatToJson(kw):
    # conn = pymysql.connect(host='localhost', user='root',
    #                        passwd='123456', db='zhifou', port=3306, charset='utf8')
    conn = POOL.connection()
    cur = conn.cursor()

    sql = "SELECT created_at FROM {}_findson".format(kw)
    cur.execute(sql)
    result = {}
    final = []
    data = cur.fetchall()

    for date_item in data:

        date_str = date_item[0].strftime('%Y-%m-%d')
        if date_str in result.keys():
            result[date_str] = result[date_str] + 1
        else:
            result[date_str] = 1

    for key in result:
        final.append([key, result[key]])

    cur.close()

    return {'data': final}


# if __name__ == "__main__":
#     print(heatToJson('双黄连'))
